package org.devgframwork.datasync.admin.support.init;

import org.devgframwork.datasync.admin.support.init.impl.*;
import org.devgframwork.datasync.core.support.DataSourceMemory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class AbstractInitializingBean implements InitializingBean, ApplicationContextAware {

    @Override
    public void afterPropertiesSet() throws Exception {
        AbstractInit canalInit = new CanalInit(null);
        AbstractInit rabbitInit = new RabbitInit(canalInit);
        AbstractInit es56Init = new Es56Init(rabbitInit);
        AbstractInit jdbcInit = new JdbcInit(es56Init);
        AbstractInit sqlInit = new SqlInit(jdbcInit);
        sqlInit.invoke();
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        DataSourceMemory.applicationContext = applicationContext;
    }
}
